<template>
    <el-dialog title="历史记录" :visible.sync="fileHistoryVisible ">
        <el-table :data="gridData" height="500" v-loading="historyLoading">
            <el-table-column property="fileName" label="文件名" width="300"></el-table-column>
            <el-table-column property="creatTime" label="创建时间"></el-table-column>
            <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                    <el-button
                            @click="downloadHistoryFile(scope.$index, scope.row)"
                            type="text"
                            size="small"
                    >下载</el-button>
                    <el-button
                            @click="previewFile(scope.row)"
                            type="text"
                            size="small"
                    >预览</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-dialog>
</template>

<script>
  export default {
    name: "FileHistory",
    data(){
      return{
        fileHistoryVisible: false,
        gridData: [],
        historyLoading:false,
      }
    },
    methods:{
      downloadHistoryFile(index, row) {
        this.$emit("downloadFile",row)
      },
      previewFile(item){
        this.$emit("previewFile",item);
      },
      /**
       * 查看上传文件的历史记录
       * @param file
       */
      fileHistory(file) {
        console.log(file);
        this.historyLoading = true;
        this.$http.get("/file/getVersionList", {
          params: {
            fileId: file.id
          }
        }).then(res => {
          console.log(res);
          if(res.data==false){
            this.$message("暂无历史记录！")
          }else{
            this.fileHistoryVisible = true;
          }
          if(res.status == 200){
            this.gridData = res.data;
          }
          this.historyLoading = false;
        });
      },
    }
  }
</script>

<style scoped>

</style>